package f;

import java.io.File;

public class FileExt {
	
	public static String getExt(File f) {
		String name = f.getName();
		int i = name.lastIndexOf(".");
		if(i!=-1) {
			return name.substring(i+1).toLowerCase();
		}
		return null;
	}
	
	public static String getNameWithoutExt(File f) {
		String name = f.getName();
		int i = name.lastIndexOf(".");
		if(i!=-1) {
			return name.substring(0, i);
		}
		return name;
	}
	
	public static final String T1 = "t";//text
	public static final String T2 = "p";//picture
	public static final String T3 = "v";//video
	public static final String T4 = "m";//music
	public static final String T5 = "b";//
	
	public static String getType(String ext) {
		if(ext!=null) {
			if("txt".equals(ext) || "java".equals(ext)
					|| "json".equals(ext) || "properties".equals(ext)) {
				return T1;
			}else if("jpg".equals(ext) || "jpeg".equals(ext)
					|| "png".equals(ext) || "bmp".equals(ext)) {
				return T2;
			}else if("mp4".equals(ext) || "rm".equals(ext)
					|| "rmvb".equals(ext) || "mov".equals(ext)
					|| "avi".equals(ext) || "3gp".equals(ext)
					|| "mkv".equals(ext) || "wmv".equals(ext)) {
				return T3;
			}else if("mp3".equals(ext) || "wav".equals(ext)
					|| "ogg".equals(ext) || "aac".equals(ext)) {
				return T4;
			}
		}
		return T5;
	}
	
	public static String getType(File f) {
		return getType(getExt(f));
	}

}
